﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.ComponentModel;
using Water.Web.Controls.BaseInterface;
using System.Drawing;
using System.Web.UI.Design;
using System.Drawing.Design;

namespace Water.Web.Controls
{
    [ToolboxData("<{0}:Toolbar runat=server></{0}:Toolbar>")]
    [ParseChildren(false), PersistChildren(true), Designer(typeof(ContainerControlDesigner))]
    public partial class Toolbar:System.Web.UI.WebControls.WebControl
    {
        private bool isDisplayTopBorder=false;
        private bool isDisplayBottomBorder=false;
        private bool isDiaplayBackground = true;


        [Browsable(true), GlobalizeDescription("IsDisplayTopBorder"), Category("Appearance"),DefaultValue(false)]
        public bool IsDisplayTopBorder
        {
            get { return isDisplayTopBorder; }
            set { isDisplayTopBorder = value; }
        }

        [Browsable(true), GlobalizeDescription("IsDisplayBottomBorder"), Category("Appearance"), DefaultValue(false)]
        public bool IsDisplayBottomBorder
        {
            get { return isDisplayBottomBorder; }
            set { isDisplayBottomBorder = value; }
        }

        [Browsable(true), GlobalizeDescription("IsDiaplayBackground"), Category("Appearance"), DefaultValue(true)]
        public bool IsDiaplayBackground
        {
            get { return isDiaplayBackground; }
            set { isDiaplayBackground = value; }
        }

        

        public Toolbar() { }

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            PageManager.Register(this);
            PageManager.RegisterPageStyleSheet(this, "Toolbar_css", "CSS/Toolbar.css");
        }
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);

            string _class = "";
            if (IsDisplayTopBorder)
                _class += " toolbar_top ";
            if (IsDisplayBottomBorder)
                _class += " toolbar_bottom ";

            if(!IsDiaplayBackground)
                writer.AddAttribute(HtmlTextWriterAttribute.Class, _class + " toolbar_n");
            else
                writer.AddAttribute(HtmlTextWriterAttribute.Class, _class + " toolbar");
        }

        protected override void RenderChildren(HtmlTextWriter writer)
        {
            if (this.HasControls())
            {
                foreach (Control c in this.Controls)
                {
                    if (DesignMode)
                        writer.AddAttribute(HtmlTextWriterAttribute.Style, "float:left");
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "toolbar_table");
                    writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
                    writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
                    writer.RenderBeginTag(HtmlTextWriterTag.Table);
                    writer.RenderBeginTag(HtmlTextWriterTag.Tr);
                    writer.RenderBeginTag(HtmlTextWriterTag.Td);
                    c.RenderControl(writer);
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                    writer.RenderEndTag();
                }
            }
            else
                base.RenderChildren(writer);
            
        }
        protected override void AddParsedSubObject(object obj)
        {
            if (!((obj is Literal && ((Literal)obj).Text.Trim().Length==0 ) || (obj is LiteralControl &&((LiteralControl)obj).Text.Trim().Length==0 )))
            base.AddParsedSubObject(obj);
        }

        public override void RenderBeginTag(HtmlTextWriter writer)
        {
            base.RenderBeginTag(writer);
        }
        public override void RenderEndTag(HtmlTextWriter writer)
        {
            base.RenderEndTag(writer);
        }
    }
}